﻿using System;
using Business.dao;
using Business.dao.conf;
using Business.entidades;
using Commons.log;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq.Expressions;
using System.Collections;


namespace EstudosTest
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        private static ILog log = CommonLog.GetLogger();

        public UnitTest1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            try
            {
                IClassificadorDAO cdao = BusinessContainer.Get<IClassificadorDAO>();
                IQueryable<Classificador> qClassificador = cdao.listar();
                IQueryable<Int64> qcMaxId = (from cl in qClassificador select cl.ClassificadorId);
                Int64 cmaxId = qcMaxId.Count() == 0 ? 0 : qcMaxId.Max();
                // Classificador c = cdao.criar();
                // c.ClassificadorId = cmaxId + 1;
                // c.Descricao = String.Format("teste {0}", cmaxId + 1);
                Classificador c = new Classificador { ClassificadorId = cmaxId + 1, Descricao = String.Format("teste {0}", cmaxId + 1) };
                log.Debug(String.Format("id: {0}, classificador:{1}", c.ClassificadorId, c.Descricao));
                c = cdao.inserir(c);

                IQuestaoDAO qqDao = BusinessContainer.Get<IQuestaoDAO>();
                qqDao.testar();
                IQueryable<Int64> qMaxId = (from questao in qqDao.listar() select questao.QuestaoId);
                Int64 maxId = qMaxId.Count() == 0 ? 0 : qMaxId.Max();
                // Questao q = qqDao.criar();
                // q.QuestaoId = (maxId) + 1;
                // q.Descricao = String.Format("questão {0}", maxId + 1);
                Questao q = new Questao { QuestaoId = (maxId) + 1, Descricao = String.Format("questão {0}", maxId + 1), Classificacao = c };
                log.Debug(String.Format("id: {0}, desc:{1}", q.QuestaoId, q.Descricao));
                q = qqDao.inserir(q);
                // q.Classificacao = cdao.buscar(c.ClassificadorId);
                // qqDao.atualizar(q);
                log.Info(q.Classificacao.Descricao);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                Assert.Fail(e.Message);
            }
        }
    }
}
